package query

import (
	"strings"

	"ssnotify/common/dto"
)

type NotifyRecordQuery struct {
	dto.Pagination `search:"-"`
	dto.OrderBy    `search:"-"`
	dto.UserInfo
	Sn         string   `form:"sn" search:"type:contains;column:sn;table:sys_notify_record"`
	Search     string   `form:"search" search:"type:likeOr;column:sn,type;table:sys_notify_record"`
	ReadStatus string   `form:"readStatus" search:"type:exact;column:read_status;table:sys_notify_record"`
	Type       string   `form:"type" search:"type:contains;column:type;table:sys_notify_record"`
	Content    string   `form:"content" search:"type:contains;column:content;table:sys_notify_record"`
	DeptId     string   `form:"deptId" search:"-"`
	Timestamp  string   `form:"timestamp" search:"-"`
	DevType    string   `form:"devType" search:"type:exact;column:dev_type;table:sys_notify_record"`
	DevTypeIn  []string `form:"devTypeIn" search:"type:in;column:dev_type;table:sys_notify_record"`

	DeptIdIn   []string `search:"type:in;column:dept_id;table:sys_notify_record"`
	StartTime  string   `search:"type:gte;column:create_time;table:sys_notify_record"`
	EndTime    string   `search:"type:lte;column:create_time;table:sys_notify_record"`
	UserIdEq   string   `search:"type:exact;column:user_id;table:sys_notify_record"`
	IdIn       []string `search:"type:in;column:id;table:sys_notify_record"`
	AgencyIdEq string   `search:"type:exact;column:agency_id;table:sys_notify_record"`
	ListFlag   string   `form:"listFlag" search:"-"` //如果传入该标识，标识查询通知管理列表，否则标识查询右上方通知记录
}

func (m *NotifyRecordQuery) GetNeedSearch() interface{} {
	if len(m.ListFlag) > 0 {
		if len(m.DeptIdList) > 0 && m.UserId != "1" {
			m.DeptIdIn = m.DeptIdList
		}
	} else {
		//admin和其他用户都只查发给自己的通知，本接口只用于页面上方的查询
		m.UserIdEq = m.UserId
	}
	if len(m.Timestamp) > 0 {
		split := strings.Split(m.Timestamp, "~")
		if len(split) == 2 {
			m.StartTime = strings.TrimSpace(split[0])
			m.EndTime = strings.TrimSpace(split[1])
		}
	}
	return *m
}
